package com.simpleframe.persistence.hibernate;

public class Condition {
	private String logic;
	private String field;
	private String operation;
	private Object value;
	private final String BLANK = " ";
	
	public String getExpression(int id){
		
		if(logic==null)logic="and";
		
		return BLANK+logic+BLANK+field+BLANK+operation+BLANK+":"+field.replaceAll("\\.", "_")+"_"+id;
	}
	
	public Object getValue() {
		if(operation.equalsIgnoreCase("like")){
			return "%"+value+"%";
		}
		return value;
	}
	
	public String getField() {
		return field;
	}
	public void setField(String field) {
		this.field = field;
	}
	
	public void setValue(Object value) {
		this.value = value;
	}
	public String getLogic() {
		return logic;
	}
	public void setLogic(String logic) {
		this.logic = logic;
	}
	public String getOperation() {
		return operation;
	}
	public void setOperation(String operation) {
		this.operation = operation;
	}
}
